//
//  YQOrderLogisticsWriteVC.m
//  MuYing
//
//  Created by tbb on 2019/8/26.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "YQOrderLogisticsWriteVC.h"
#import "MYMyUserInfoEditTextFieldCell.h"
@interface YQOrderLogisticsWriteVC ()
@property (nonatomic, strong) UITextField * nameTextField;
@property (nonatomic, strong) UITextField * numTextField;
@end

@implementation YQOrderLogisticsWriteVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isNavShadow = YES;
    self.navigationItem.title = kYQLS(@"物流信息填写");
    self.rightItemTitle = kYQLS(@"提交");
    self.listTableView.bounces = NO;
}

-(void)rightItemAction:(UIButton *)sender {
    
    if ([self.nameTextField.text removeStringSpace].length == 0) {
        kMBMesHUD(kYQLS(@"请输入物流公司名字"))
        return;
    }
    
    if ([self.numTextField.text removeStringSpace].length == 0) {
        kMBMesHUD(kYQLS(@"请输入物流单号"))
        return;
    }
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"logisticsName"] = self.nameTextField.text;
    parameters[@"logisticsCode"] = self.numTextField.text;
    parameters[@"refundId"] = @"0";
    parameters[@"orderType"] = @(self.detailModel.orderType);

    YQSHOWLOADINGTIPS(kYQLS(@"正在提交"))
    [YQPNetWorkingManager sendPostRequest:kPOST_REFUND_SUBMIT_LOGISTICS_URL parameters:parameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        YQHIDELOADINGTIPS
        if (responseObject.code == 0) {
            YQUITIPSSUCCEED(responseObject.msg)
            [self.navigationController popViewControllerAnimated:true];
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQUITIPSERROR(error)
        YQHIDELOADINGTIPS
    }];
    
}

-(void)setupView {
    [super setupView];
    
    kYQREGISTERTABLEVIEWNIBCELL(@"MYMyUserInfoEditTextFieldCell")
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    MYMyUserInfoEditTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYMyUserInfoEditTextFieldCell"];
    if (indexPath.row == 0) {
        cell.textField.placeholder = kYQLS(@"请输入物流公司名称");
        self.nameTextField = cell.textField;
    }else{
        cell.textField.placeholder = kYQLS(@"请输入物流单号");
        self.numTextField = cell.textField;
    }
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 58;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end
@end
